﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using PoemsSystem;
namespace PoemsSystem
{
    public partial class InfoReact : Form
    {

        public InfoReact()
        {
            InitializeComponent();
        }


        private void btnAuthorInfo_Click(object sender, EventArgs e)
        {
            string PoetName, PoetInformation;
            PoetName = IDPoetName.Text;
            PoetInformation = IDPoetInformation.Text;
            if (PoetName == "" || PoetInformation == "")
            {
                MessageBox.Show("请输入完整信息", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                string connString = @"Data Source = MSI\SQLEXPRESS;
                                Database = master;
                                AttachDbFilename = D:\SQLserver\MSSQL15.SQLEXPRESS\MSSQL\DATA\master.mdf;
                                Integrated Security = True;";
                SqlConnection connection = new SqlConnection(connString);
                connection.Open();
                String commandTextQuery = "insert into dbo.author values('" + PoetName + "', '" + PoetInformation + "')";
                SqlCommand cmdQuery = new SqlCommand(commandTextQuery, connection);
                int result = cmdQuery.ExecuteNonQuery();
                if (result == 1)
                {
                    MessageBox.Show("信息已成功提交", "提示", MessageBoxButtons.OK);
                }
                //cmdQuery.Close();   不知道为什么，找不到Close，但是网上能够Close
                //cmdQuery.Dispose();
            }
        }

        private void btnPoemInfo_Click(object sender, EventArgs e)
        {
            string PoetName, PoemName, PoemSource;
            PoetName = IDPoetName.Text;
            PoemName = IDPoemTitle.Text;
            PoemSource = IDPoemData.Text;
            if (PoetName == "" || PoemName == "" || PoemSource == "")
            {
                MessageBox.Show("请输入完整信息", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                string connString = @"Data Source = MSI\SQLEXPRESS;
                                Database = master;
                                AttachDbFilename = D:\SQLserver\MSSQL15.SQLEXPRESS\MSSQL\DATA\master.mdf;
                                Integrated Security = True;";
                SqlConnection connection = new SqlConnection(connString);
                connection.Open();
                String commandTextQuery = "insert into dbo.poem values('" + PoetName + "', '" + PoemName + "', '" + PoemSource + "')";
                SqlCommand cmdQuery = new SqlCommand(commandTextQuery, connection);
                int result = cmdQuery.ExecuteNonQuery();
                if (result == 1)
                {
                    MessageBox.Show("信息已成功提交", "提示", MessageBoxButtons.OK);
                }
                //cmdQuery.Close();   不知道为什么，找不到Close，但是网上能够Close
                //cmdQuery.Dispose();
            }

        }
    }
}
